]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
Port client side code to GDBus
authorGiovanni Campagna <gcampagna@src.gnome.org>
Tue, 16 Aug 2011 12:28:53 +0000 (14:28 +0200)
committerColin Walters <walters@verbum.org>
Fri, 11 Nov 2011 16:15:38 +0000 (11:15 -0500)
This continues the series of patches for GDBus porting, affecting
all code that accesses remote DBus objects. This includes modemManager,
automount, autorun (for the hotplug sniffer), calendar, network (for
nm-applet only), power, scripting (for perf monitor interface)

https://bugzilla.gnome.org/show_bug.cgi?id=648651

js/misc/modemManager.js
js/ui/automountManager.js
js/ui/autorunManager.js
js/ui/calendar.js
js/ui/scripting.js
js/ui/status/power.js

index 6fb2e2c76abc0a0c3d168e89b1ce212696b0cb8a..d04a3ab65009de0afcbc7b14c2268590e0820fb1 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 
-const DBus = imports.dbus;
+const Gio = imports.gi.Gio;
 const Lang = imports.lang;
 const Shell = imports.gi.Shell;
 const Signals = imports.signals;
@@ -8,33 +8,43 @@ const Signals = imports.signals;
 // The following are not the complete interfaces, just the methods we need
 // (or may need in the future)
 
-const ModemGsmNetworkInterface = {
-    name: 'org.freedesktop.ModemManager.Modem.Gsm.Network',
-    methods: [
-        { name: 'GetRegistrationInfo', inSignature: '', outSignature: 'uss' },
-        { name: 'GetSignalQuality', inSignature: '', outSignature: 'u' }
-    ],
-    properties: [
-        { name: 'AccessTechnology', signature: 'u', access: 'read' }
-    ],
-    signals: [
-        { name: 'SignalQuality', inSignature: 'u' },
-        { name: 'RegistrationInfo', inSignature: 'uss' }
-    ]
-};
-const ModemGsmNetworkProxy = DBus.makeProxyClass(ModemGsmNetworkInterface);
-
-const ModemCdmaInterface = {
-    name: 'org.freedesktop.ModemManager.Modem.Cdma',
-    methods: [
-        { name: 'GetSignalQuality', inSignature: '', outSignature: 'u' },
-        { name: 'GetServingSystem', inSignature: '', outSignature: 'usu' }
-    ],
-    signals: [
-        { name: 'SignalQuality', inSignature: 'u' }
-    ]
-};
-const ModemCdmaProxy = DBus.makeProxyClass(ModemCdmaInterface);
+const ModemGsmNetworkInterface = <interface name="org.freedesktop.ModemManager.Modem.Gsm.Network">
+<method name="GetRegistrationInfo">
+    <arg type="u" direction="out" />
+    <arg type="s" direction="out" />
+    <arg type="s" direction="out" />
+</method>
+<method name="GetSignalQuality">
+    <arg type="u" direction="out" />
+</method>
+<property name="AccessTechnology" type="u" access="read" />
+<signal name="SignalQuality">
+    <arg type="u" direction="out" />
+</signal>
+<signal name="RegistrationInfo">
+    <arg type="u" direction="out" />
+    <arg type="s" direction="out" />
+    <arg type="s" direction="out" />
+</signal>
+</interface>;
+
+const ModemGsmNetworkProxy = Gio.DBusProxy.makeProxyWrapper(ModemGsmNetworkInterface);
+
+const ModemCdmaInterface = <interface name="org.freedesktop.ModemManager.Modem.Cdma">
+<method name="GetSignalQuality">
+    <arg type="u" direction="out" />
+</method>
+<method name="GetServingSystem">
+    <arg type="u" direction="out" />
+    <arg type="s" direction="out" />
+    <arg type="u" direction="out" />
+</method>
+<signal name="SignalQuality">
+    <arg type="u" direction="out" />
+</signal>
+</interface>;
+
+const ModemCdmaProxy = Gio.DBusProxy.makeProxyWrapper(ModemCdmaInterface);
 
 let _providersTable;
 function _getProvidersTable() {
@@ -50,17 +60,17 @@ function ModemGsm() {
 
 ModemGsm.prototype = {
     _init: function(path) {
-        this._proxy = new ModemGsmNetworkProxy(DBus.system, 'org.freedesktop.ModemManager', path);
+        this._proxy = new ModemGsmNetworkProxy(Gio.DBus.system, 'org.freedesktop.ModemManager', path);
 
         this.signal_quality = 0;
         this.operator_name = null;
 
         // Code is duplicated because the function have different signatures
-        this._proxy.connect('SignalQuality', Lang.bind(this, function(proxy, quality) {
+        this._proxy.connectSignal('SignalQuality', Lang.bind(this, function(proxy, sender, [quality]) {
             this.signal_quality = quality;
             this.emit('notify::signal-quality');
         }));
-        this._proxy.connect('RegistrationInfo', Lang.bind(this, function(proxy, status, code, name) {
+        this._proxy.connectSignal('RegistrationInfo', Lang.bind(this, function(proxy, sender, [status, code, name]) {
             this.operator_name = this._findOperatorName(name, code);
             this.emit('notify::operator-name');
         }));
@@ -155,12 +165,12 @@ function ModemCdma() {
 
 ModemCdma.prototype = {
     _init: function(path) {
-        this._proxy = new ModemCdmaProxy(DBus.system, 'org.freedesktop.ModemManager', path);
+        this._proxy = new ModemCdmaProxy(Gio.DBus.system, 'org.freedesktop.ModemManager', path);
 
         this.signal_quality = 0;
         this.operator_name = null;
-        this._proxy.connect('SignalQuality', Lang.bind(this, function(proxy, quality) {
-            this.signal_quality = quality;
+        this._proxy.connect('SignalQuality', Lang.bind(this, function(proxy, sender, params) {
+            this.signal_quality = params[0];
             this.emit('notify::signal-quality');
 
             // receiving this signal means the device got activated
index e3dfe4dda92690fde6f764eba44a3245b74393ac..456e0426940a3ff79543b4a1c9ec3d9b88594bee 100644 (file)
@@ -1,7 +1,6 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 
 const Lang = imports.lang;
-const DBus = imports.dbus;
 const Mainloop = imports.mainloop;
 const Gio = imports.gi.Gio;
 const Params = imports.misc.params;
@@ -16,63 +15,54 @@ const SETTING_ENABLE_AUTOMOUNT = 'automount';
 
 const AUTORUN_EXPIRE_TIMEOUT_SECS = 10;
 
-const ConsoleKitSessionIface = {
-    name: 'org.freedesktop.ConsoleKit.Session',
-    methods: [{ name: 'IsActive',
-                inSignature: '',
-                outSignature: 'b' }],
-    signals: [{ name: 'ActiveChanged',
-                inSignature: 'b' }]
-};
+const ConsoleKitSessionIface = <interface name="org.freedesktop.ConsoleKit.Session">
+<method name="IsActive">
+    <arg type="b" direction="out" />
+</method>
+<signal name="ActiveChanged">
+    <arg type="b" direction="out" />
+</signal>
+</interface>;
 
-const ConsoleKitSessionProxy = DBus.makeProxyClass(ConsoleKitSessionIface);
+const ConsoleKitSessionProxy = Gio.DBusProxy.makeProxyWrapper(ConsoleKitSessionIface);
 
-const ConsoleKitManagerIface = {
-    name: 'org.freedesktop.ConsoleKit.Manager',
-    methods: [{ name: 'GetCurrentSession',
-                inSignature: '',
-                outSignature: 'o' }]
-};
+const ConsoleKitManagerIface = <interface name="org.freedesktop.ConsoleKit.Manager">
+<method name="GetCurrentSession">
+    <arg type="o" direction="out" />
+</method>
+</interface>;
 
-function ConsoleKitManager() {
-    this._init();
-};
-
-ConsoleKitManager.prototype = {
-    _init: function() {
-        this.sessionActive = true;
-
-        DBus.system.proxifyObject(this,
-                                  'org.freedesktop.ConsoleKit',
-                                  '/org/freedesktop/ConsoleKit/Manager');
+const ConsoleKitManagerInfo = Gio.DBusInterfaceInfo.new_for_xml(ConsoleKitManagerIface);
 
-        DBus.system.watch_name('org.freedesktop.ConsoleKit',
-                               false, // do not launch a name-owner if none exists
-                               Lang.bind(this, this._onManagerAppeared),
-                               Lang.bind(this, this._onManagerVanished));
-    },
-
-    _onManagerAppeared: function(owner) {
-        this.GetCurrentSessionRemote(Lang.bind(this, this._onCurrentSession));
-    },
-
-    _onManagerVanished: function(oldOwner) {
-        this.sessionActive = true;
-    },
-
-    _onCurrentSession: function(session) {
-        this._ckSession = new ConsoleKitSessionProxy(DBus.system, 'org.freedesktop.ConsoleKit', session);
+function ConsoleKitManager() {
+    var self = new Gio.DBusProxy({ g_connection: Gio.DBus.system,
+                                  g_interface_name: ConsoleKitManagerInfo.name,
+                                  g_interface_info: ConsoleKitManagerInfo,
+                                  g_name: 'org.freedesktop.ConsoleKit',
+                                  g_object_path: '/org/freedesktop/ConsoleKit/Manager',
+                                   g_flags: (Gio.DBusProxyFlags.DO_NOT_AUTO_START |
+                                             Gio.DBusProxyFlags.DO_NOT_LOAD_PROPERTIES) });
+
+    self.connect('notify::g-name-owner', function() {
+        if (self.g_name_owner) {
+            self.GetCurrentSessionRemote(function([session]) {
+                self._ckSession = new ConsoleKitSessionProxy(Gio.DBus.system, 'org.freedesktop.ConsoleKit', session);
+
+                self._ckSession.connectSignal('ActiveChanged', function(object, senderName, [isActive]) {
+                    self.sessionActive = isActive;
+                });
+                self._ckSession.IsActiveRemote(function([isActive]) {
+                    self.sessionActive = isActive;
+                });
+            });
+        } else {
+            self.sessionActive = true;
+        }
+    });
 
-        this._ckSession.connect
-            ('ActiveChanged', Lang.bind(this, function(object, isActive) {
-                this.sessionActive = isActive;            
-            }));
-        this._ckSession.IsActiveRemote(Lang.bind(this, function(isActive) {
-            this.sessionActive = isActive;            
-        }));
-    }
-};
-DBus.proxifyPrototype(ConsoleKitManager.prototype, ConsoleKitManagerIface);
+    self.init(null);
+    return self;
+}
 
 function AutomountManager() {
     this._init();
index 71e51e6ce608279d3fd5dd0386e35fc507c24a97..2cc13c510507a422f2b4320bd99e536035b10b25 100644 (file)
@@ -1,7 +1,6 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 
 const Lang = imports.lang;
-const DBus = imports.dbus;
 const Gio = imports.gi.Gio;
 const St = imports.gi.St;
 
@@ -62,25 +61,19 @@ function startAppForMount(app, mount) {
 
 /******************************************/
 
-const HotplugSnifferIface = {
-    name: 'org.gnome.Shell.HotplugSniffer',
-    methods: [{ name: 'SniffURI',
-                inSignature: 's',
-                outSignature: 'as' }]
-};
-
-const HotplugSniffer = function() {
-    this._init();
-};
+const HotplugSnifferIface = <interface name="org.gnome.Shell.HotplugSniffer">
+<method name="SniffURI">
+    <arg type="s" direction="in" />
+    <arg type="as" direction="out" />
+</method>
+</interface>;
 
-HotplugSniffer.prototype = {
-    _init: function() {
-        DBus.session.proxifyObject(this,
+const HotplugSnifferProxy = Gio.DBusProxy.makeProxyWrapper(HotplugSnifferIface);
+function HotplugSniffer() {
+    return new HotplugSnifferProxy(Gio.DBus.session,
                                    'org.gnome.Shell.HotplugSniffer',
                                    '/org/gnome/Shell/HotplugSniffer');
-    },
-};
-DBus.proxifyPrototype(HotplugSniffer.prototype, HotplugSnifferIface);
+}
 
 function ContentTypeDiscoverer(callback) {
     this._init(callback);
@@ -114,9 +107,8 @@ ContentTypeDiscoverer.prototype = {
             let root = mount.get_root();
 
             let hotplugSniffer = new HotplugSniffer();
-            hotplugSniffer.SniffURIRemote
-                (root.get_uri(), DBus.CALL_FLAG_START,
-                 Lang.bind(this, function(contentTypes) {
+            hotplugSniffer.SniffURIRemote(root.get_uri(),
+                 Lang.bind(this, function([contentTypes]) {
                      this._emitCallback(mount, contentTypes);
                  }));
         }
index cec7b259658e2d782a349e97300d5c1c179e95c7..98ae634e64bdec565a2c76014319e0fde19d28f4 100644 (file)
@@ -1,6 +1,5 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 
-const DBus = imports.dbus;
 const Clutter = imports.gi.Clutter;
 const Gio = imports.gi.Gio;
 const Lang = imports.lang;
@@ -195,30 +194,34 @@ EmptyEventSource.prototype = {
 };
 Signals.addSignalMethods(EmptyEventSource.prototype);
 
-const CalendarServerIface = {
-    name: 'org.gnome.Shell.CalendarServer',
-    methods: [{ name: 'GetEvents',
-                inSignature: 'xxb',
-                outSignature: 'a(sssbxxa{sv})' }],
-    signals: [{ name: 'Changed',
-                inSignature: '' }]
-};
-
-const CalendarServer = function () {
-    this._init();
-};
-
-CalendarServer.prototype = {
-     _init: function() {
-         DBus.session.proxifyObject(this, 'org.gnome.Shell.CalendarServer', '/org/gnome/Shell/CalendarServer');
-     }
-};
-
-DBus.proxifyPrototype(CalendarServer.prototype, CalendarServerIface);
+const CalendarServerIface = <interface name="org.gnome.Shell.CalendarServer">
+<method name="GetEvents">
+    <arg type="x" direction="in" />
+    <arg type="x" direction="in" />
+    <arg type="b" direction="in" />
+    <arg type="a(sssbxxa{sv})" direction="out" />
+</method>
+<signal name="Changed" />
+</interface>;
+
+const CalendarServerInfo  = Gio.DBusInterfaceInfo.new_for_xml(CalendarServerIface);
+
+function CalendarServer() {
+    var self = new Gio.DBusProxy({ g_connection: Gio.DBus.session,
+                                  g_interface_name: CalendarServerInfo.name,
+                                  g_interface_info: CalendarServerInfo,
+                                  g_name: 'org.gnome.Shell.CalendarServer',
+                                  g_object_path: '/org/gnome/Shell/CalendarServer',
+                                   g_flags: (Gio.DBusProxyFlags.DO_NOT_AUTO_START |
+                                             Gio.DBusProxyFlags.DO_NOT_LOAD_PROPERTIES) });
+
+    self.init(null);
+    return self;
+}
 
 // an implementation that reads data from a session bus service
-function DBusEventSource(owner) {
-    this._init(owner);
+function DBusEventSource() {
+    this._init();
 }
 
 function _datesEqual(a, b) {
@@ -241,16 +244,18 @@ function _dateIntervalsOverlap(a0, a1, b0, b1)
 
 
 DBusEventSource.prototype = {
-    _init: function(owner) {
+    _init: function() {
         this._resetCache();
 
-        this._dbusProxy = new CalendarServer(owner);
-        this._dbusProxy.connect('Changed', Lang.bind(this, this._onChanged));
+        this._dbusProxy = new CalendarServer();
+        this._dbusProxy.connectSignal('Changed', Lang.bind(this, this._onChanged));
 
-        DBus.session.watch_name('org.gnome.Shell.CalendarServer',
-                                false, // do not launch a name-owner if none exists
-                                Lang.bind(this, this._onNameAppeared),
-                                Lang.bind(this, this._onNameVanished));
+        this._dbusProxy.connect('notify::g-name-owner', Lang.bind(this, function() {
+            if (this._dbusProxy.g_name_owner)
+                this._onNameAppeared();
+            else
+                this._onNameVanished();
+        }));
     },
 
     _resetCache: function() {
@@ -273,7 +278,7 @@ DBusEventSource.prototype = {
         this._loadEvents(false);
     },
 
-    _onEventsReceived: function(appointments) {
+    _onEventsReceived: function([appointments]) {
         let newEvents = [];
         if (appointments != null) {
             for (let n = 0; n < appointments.length; n++) {
@@ -296,9 +301,9 @@ DBusEventSource.prototype = {
 
     _loadEvents: function(forceReload) {
         if (this._curRequestBegin && this._curRequestEnd){
-            let callFlags = 0;
+            let callFlags = Gio.DBusCallFlags.NO_AUTO_START;
             if (forceReload)
-                callFlags |= DBus.CALL_FLAG_START;
+                callFlags = Gio.DBusCallFlags.NONE;
             this._dbusProxy.GetEventsRemote(this._curRequestBegin.getTime() / 1000,
                                             this._curRequestEnd.getTime() / 1000,
                                             forceReload,
index 3b8e4452117bdcd57f1b6ea6361552e8d70b3490..d5e2eaee640073fc931f3e423f85501060cc0319 100644 (file)
@@ -1,6 +1,5 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 
-const DBus = imports.dbus;
 const Gio = imports.gi.Gio;
 const Mainloop = imports.mainloop;
 const Meta = imports.gi.Meta;
@@ -70,24 +69,21 @@ function waitLeisure() {
     };
 }
 
-const PerfHelperIface = {
-    name: 'org.gnome.Shell.PerfHelper',
-    methods: [{ name: 'CreateWindow', inSignature: 'iibb', outSignature: '' },
-              { name: 'WaitWindows', inSignature: '', outSignature: '' },
-              { name: 'DestroyWindows', inSignature: '', outSignature: ''}]
-};
-
-const PerfHelper = function () {
-    this._init();
-};
-
-PerfHelper.prototype = {
-     _init: function() {
-         DBus.session.proxifyObject(this, 'org.gnome.Shell.PerfHelper', '/org/gnome/Shell/PerfHelper');
-     }
-};
-
-DBus.proxifyPrototype(PerfHelper.prototype, PerfHelperIface);
+const PerfHelperIface = <interface name="org.gnome.Shell.PerfHelper">
+<method name="CreateWindow">
+    <arg type="i" direction="in" />
+    <arg type="i" direction="in" />
+    <arg type="b" direction="in" />
+    <arg type="b" direction="in" />
+</method>
+<method name="WaitWindows" />
+<method name="DestroyWindows" />
+</interface>;
+
+var PerfHelperProxy = Gio.DBusProxy.makeProxyWrapper(PerfHelperIface);
+function PerfHelper() {
+    return new PerfHelperProxy(Gio.DBus.session, 'org.gnome.Shell.PerfHelper', '/org/gnome/Shell/PerfHelper');
+}
 
 let _perfHelper = null;
 function _getPerfHelper() {
index aee22e9aac7bf13a97a58ed124346b6d6f822fa5..fa77d552aa164801545ccab0528ed954b2a5176c 100644 (file)
@@ -1,7 +1,6 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 
 const Gio = imports.gi.Gio;
-const DBus = imports.dbus;
 const Lang = imports.lang;
 const Mainloop = imports.mainloop;
 const Shell = imports.gi.Shell;
@@ -40,20 +39,18 @@ const UPDeviceState = {
     PENDING_DISCHARGE: 6
 };
 
-const PowerManagerInterface = {
-    name: 'org.gnome.SettingsDaemon.Power',
-    methods: [
-        { name: 'GetDevices', inSignature: '', outSignature: 'a(susdut)' },
-        { name: 'GetPrimaryDevice', inSignature: '', outSignature: '(susdut)' },
-        ],
-    signals: [
-        { name: 'Changed', inSignature: '' },
-        ],
-    properties: [
-        { name: 'Icon', signature: 's', access: 'read' },
-        ]
-};
-let PowerManagerProxy = DBus.makeProxyClass(PowerManagerInterface);
+const PowerManagerInterface = <interface name="org.gnome.SettingsDaemon.Power">
+<method name="GetDevices">
+    <arg type="a(susdut)" direction="out" />
+</method>
+<method name="GetPrimaryDevice">
+    <arg type="(susdut)" direction="out" />
+</method>
+<signal name="Changed" />
+<property name="Icon" type="s" access="read" />
+</interface>;
+
+const PowerManagerProxy = Gio.DBusProxy.makeProxyWrapper(PowerManagerInterface);
 
 function Indicator() {
     this._init.apply(this, arguments);
@@ -64,7 +61,7 @@ Indicator.prototype = {
 
     _init: function() {
         PanelMenu.SystemStatusButton.prototype._init.call(this, 'battery-missing');
-        this._proxy = new PowerManagerProxy(DBus.session, BUS_NAME, OBJECT_PATH);
+        this._proxy = new PowerManagerProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH);
 
         this._deviceItems = [ ];
         this._hasPrimary = false;
@@ -81,19 +78,19 @@ Indicator.prototype = {
         this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
         this.menu.addSettingsAction(_("Power Settings"), 'gnome-power-panel.desktop');
 
-        this._proxy.connect('Changed', Lang.bind(this, this._devicesChanged));
+        this._proxy.connectSignal('Changed', Lang.bind(this, this._devicesChanged));
         this._devicesChanged();
     },
 
     _readPrimaryDevice: function() {
-        this._proxy.GetPrimaryDeviceRemote(Lang.bind(this, function(device, error) {
+        this._proxy.GetPrimaryDeviceRemote(Lang.bind(this, function(result, error) {
             if (error) {
                 this._hasPrimary = false;
                 this._primaryDeviceId = null;
                 this._batteryItem.actor.hide();
                 return;
             }
-            let [device_id, device_type, icon, percentage, state, seconds] = device;
+            let [[device_id, device_type, icon, percentage, state, seconds]] = result;
             if (device_type == UPDeviceType.BATTERY) {
                 this._hasPrimary = true;
                 let time = Math.round(seconds / 60);
@@ -130,7 +127,7 @@ Indicator.prototype = {
     },
 
     _readOtherDevices: function() {
-        this._proxy.GetDevicesRemote(Lang.bind(this, function(devices, error) {
+        this._proxy.GetDevicesRemote(Lang.bind(this, function(result, error) {
             this._deviceItems.forEach(function(i) { i.destroy(); });
             this._deviceItems = [];
 
@@ -139,6 +136,7 @@ Indicator.prototype = {
             }
 
             let position = 0;
+            let [devices] = result;
             for (let i = 0; i < devices.length; i++) {
                 let [device_id, device_type] = devices[i];
                 if (device_type == UPDeviceType.AC_POWER || device_id == this._primaryDeviceId)
@@ -153,16 +151,15 @@ Indicator.prototype = {
     },
 
     _devicesChanged: function() {
-        this._proxy.GetRemote('Icon', Lang.bind(this, function(icon, error) {
-            if (icon) {
-                let gicon = Gio.icon_new_for_string(icon);
-                this.setGIcon(gicon);
-                this.actor.show();
-            } else {
-                this.menu.close();
-                this.actor.hide();
-            }
-        }));
+        let icon = this._proxy.Icon;
+        if (icon) {
+            let gicon = Gio.icon_new_for_string(icon);
+            this.setGIcon(gicon);
+            this.actor.show();
+        } else {
+            this.menu.close();
+            this.actor.hide();
+        }
         this._readPrimaryDevice();
         this._readOtherDevices();
     }